package projectManagementServer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class PackMessage {
	private String sender;
	private String avatar;
	private String message;
	private String time;
	private int length;
	
	private Editor editor;
	
	public PackMessage(String sender, String avatar, String message, String time, int length){
		this.sender = sender;
		this.avatar = avatar;
		this.message = message;
		this.time = time;
		this.length = length;
		editor = new Editor();
	}
	
	public JPanel getInstance(){
		JPanel msg = new JPanel();
		JPanel prof = new JPanel();

		ImageIcon icon = new ImageIcon(avatar);
		JLabel pic = new JLabel(icon);
		pic.setPreferredSize(new Dimension(64,64));
		
		JLabel name = new JLabel(sender);
		name.setPreferredSize(new Dimension(64,10));
		name.setHorizontalAlignment(SwingConstants.CENTER);
		
		prof.setLayout(new FlowLayout(FlowLayout.LEADING));
		prof.setBackground(new Color(175, 238, 238));
		prof.setPreferredSize(new Dimension(75,100));
		prof.setOpaque(true);

		prof.add(pic);
		prof.add(name);
		
		msg.setBackground(new Color(230, 230, 250));
		msg.setOpaque(true);
		msg.setLayout(new FlowLayout(FlowLayout.LEADING));
		msg.setPreferredSize(new Dimension(560, length+50));
		
		editor.setPreferredSize(new Dimension(470, length));
		msg.add(prof);
		msg.add(editor);
		editor.setText(message+" -"+time);
		return msg;
	}

}
